package com.xayy.ha.gen.lite.mapper;

import com.xayy.ha.gen.lite.entity.GenTabInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @ClasssName CodeGenerateMapper
 * @Description 代码生成mapper
 * @Author Liuyh
 * @Date 2021/5/12
 * @Version V0.0.1
 */
@Mapper
@Component
public interface SqliteTableMapper {


    /**
     * 查询表信息
     *
     * @param tableName 表名称
     * @return
     */
    @Select("" +
            " select tbl_name tableName, " +
            "  name tableComment, " +
            "  CURRENT_DATE createTime " +
            "  from sqlite_master " +
            " where type = 'table' and tbl_name = #{tableName}" +
            "")
    GenTabInfo selectTableInfo(@Param("tableName") String tableName);



//    @Select("" +
//            "SELECT " +
//            "    column_name columnName, " +
//            "    data_type dataType, " +
//            "    column_comment fieldComment, " +
//            "    column_key columnKey, " +
//            "    extra, " +
//            "    is_nullable AS isNullable, " +
//            "    column_type AS columnType " +
//            "FROM " +
//            "    information_schema.COLUMNS " +
//            "WHERE " +
//            "    table_name = #{tableName} and table_schema = (select database()) order by ordinal_position" +
//            "")
    @Select("PRAGMA table_info(${tableName})")
    List<Map<String,Object>> selectTableColumn(@Param("tableName") String tableName);
}